<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'detail';
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请选择课程','error','jy_xiaoeknow/index/');
	}
	$this->session('id',$id);
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'id'=>$id);
	if($_RQ['keyword']){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
	}
	$item=pdo_get('jy_xiaoeknow_video_jieitem',$params);
	if($item['status']!=1){
		exi('该课程已经关闭！','error','jy_xiaoeknow/index/');
	}
	$video=pdo_get('jy_xiaoeknow_video',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['video_id']));
	if($video['isjie'] && $item['jie_id']){
		$return['jie']=pdo_get('jy_xiaoeknow_video_jie',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['jie_id']));
	}else{
		$return['jie']=$video;
		$return['jie']['feetype']=$video['type'];
		pdo_update('jy_xiaoeknow_video_jieitem',array('readnum +='=>1),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	}	
	$item['createtime']=date('Y-m-d',$item['createtime']);
	$item['image']=tomedia($item['image']);
	if(strpos($item['videourl'],'<iframe') !==false){
		$item['isiframe']=1;
	}else{
		$item['videourl']=tomedia($item['videourl']);
	}
	$item['images']=json_decode($item['images'],true)?:array();
	if($return['jie']['feetype']){
		$item['feetype']=$return['jie']['feetype'];
		$item['price']=$return['jie']['price'];
	}
	$return['video']=$video;
	$return['item']=$item;
	//判断是否点赞：
	$return['islike']=pdo_getcolumn('jy_xiaoeknow_video_log',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid'],'jieitem_id'=>$id),'islike');
	$return['isshoucang']=pdo_getcolumn('jy_xiaoeknow_shoucang',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid'],'oid'=>$item['video_id']),'isshoucang');
	$return['params']=array('noread_id'=>$item['noread_id'],'noread_type'=>$item['noread_type'],'item_id'=>$item['id'],'jie_id'=>$item['jie_id'],'merchid'=>$_SESSION['onemerchid'],'video_id'=>$item['video_id']);
	$return['post']=$return['params'];
	$return['showtype']=0;
	//付费
	//是否付费
	$return['isvip']=$this->model('model')->checkvip();
	$return['item']=$this->model('model')->checknoread($return['item'],$return['isvip'],$return['jie']);
	//浏览权限
	$levelinfo = model('jy_weishop/member')->get_level();
	if($item['showlevels']){
			$fastvalue=substr($item['showlevels'],0,1);
			if($fastvalue!=';'){
				$item['showlevels']=';'.$item['showlevels'];
			}
			$lastvalue=substr($item['showlevels'],-1,1);
			if($lastvalue!=';'){
				$item['showlevels']=$item['showlevels'].';';
			}
			if(strpos($item['showlevels'],';'.$levelinfo['id'].';')===false){
				exi('您没有权限浏览该内容！','error','jy_xiaoeknow/video_detail//id='.$item['video_id']);
			}
	}
	$return['sharedata']=array(
		'title'=>$item['title']?$item['title']:'课件详情',
		'desc'=>$item['desc']?$item['desc']:'课件说明',
		'link'=>custom_url('jy_xiaoeknow/video_jieitem//id='.$id,true),
		'imgUrl'=>tomedia($item['image']),
	);
	set_html('title',$item['title']);
	exi($return);
}
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'merchid'=>$_SESSION['onemerchid']);
	if($_RQ['jie_id']){
		$params['jie_id']=$_RQ['jie_id'];
	}
	if($_RQ['video_id']){
		$params['video_id']=$_RQ['video_id'];
	}
	if($_RQ['keyword']){
		$params['keyword']=$_RQ['keyword'];
	}
	$fields=array('id','title','video_id','jie_id','image','desc','type','videourl','times','readnum','status','star','xuanxiu','updatetime','createtime');
	$pindex = max(1, intval($_RQ['page']));
	$psize = 8;
	$list=pdo_getslice('jy_xiaoeknow_video_jieitem',$params,array($pindex,$psize),$total,$fields,'','paixu desc');
	foreach($list as &$item){
		$item['image']=tomedia($item['image']);
		$item['createtime']=date('Y-m-d',$item['createtime']);
		$item['typetitle']=$this->content_types[$item['type']];
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='like'){
	$post=get_postdata();
	$id = $post['id'];
	$like=pdo_get('jy_xiaoeknow_video_log',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'merchid'=>$_SESSION['onemerchid'],'jieitem_id'=>$id),array('id','islike'));
	if($like['id']){
			$islike=$like['islike']?0:1;
			pdo_update('jy_xiaoeknow_video_log',array('islike'=>$islike),array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'jieitem_id'=>$id));
			exi($islike?'点赞成功':'取消成功');
	}else{
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'merchid'=>$_SESSION['onemerchid'],
			'mid'=>$_SESSION['uid'],
			'islike'=>1,
			'jieitem_id'=>$id,
			'createtime'=>TIMESTAMP
		);
		pdo_insert('jy_xiaoeknow_video_log',$insert);
		exi('点赞成功');
	}
}
?>